
from PyQt5 import QtCore, QtGui, QtWidgets
from component.VoiceRecorderWidget import RecorderWidget
from component.TextReader import TextReader

class ProblemAndRecordWidget(QtWidgets.QWidget):
    def __init__(self,problemText,name=''):
        super(ProblemAndRecordWidget, self).__init__()
        self.problemText = problemText
        self.name = name
        self.setupUI()

    def setupUI(self):
        self.vbox = QtWidgets.QVBoxLayout(self)

        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setContentsMargins(0,0,0,0)
        self.gridLayout.setObjectName("gridLayout")
        self.tingli_text = QtWidgets.QTextBrowser(self)
        # self.tingli_text.setMinimumSize(QtCore.QSize(300, 40))
        self.tingli_text.setMaximumSize(QtCore.QSize(999, 100))
        self.tingli_text.setStyleSheet("#tingli_text{\n"
                                       "    background-color:#F1F0F0;\n"
                                       "}")
        self.tingli_text.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.tingli_text.setFrameShadow(QtWidgets.QFrame.Plain)
        self.tingli_text.setLineWidth(0)
        self.tingli_text.setObjectName("tingli_text")
        self.gridLayout.addWidget(self.tingli_text, 0, 1, 1, 1)

        self.bofang = QtWidgets.QPushButton(self)
        # self.bofang.setMinimumSize(QtCore.QSize(0, 40))
        self.bofang.setMaximumSize(QtCore.QSize(130, 40))
        self.bofang.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.bofang.setStyleSheet("#bofang{\n"
                                  "    background-color:transparent;\n"
                                  "    border-radius:10px;\n"
                                  "border-color:white;\n"
                                  "margin-left:5px;\n"
                                  "color:#3DA19F;\n"
                                  "}")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("./imgs/broadcast2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.bofang.setIcon(icon)
        self.bofang.setIconSize(QtCore.QSize(30, 30))
        self.bofang.setObjectName("bofang")
        self.gridLayout.addWidget(self.bofang, 0, 0, 1, 1)


        # self.stop_bofang = QtWidgets.QPushButton(self)
        # self.stop_bofang.setMinimumSize(QtCore.QSize(0, 20))
        # self.stop_bofang.setMaximumSize(QtCore.QSize(100, 40))
        # self.stop_bofang.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        # self.stop_bofang.setStyleSheet("#stop_bofang\n"
        #                                "{\n"
        #                                "    background-color:transparent;\n"
        #                                "    border-radius:10px;\n"
        #                                "border-color:white\n"
        #                                "}")
        # icon1 = QtGui.QIcon()
        # icon1.addPixmap(QtGui.QPixmap("./imgs/stop.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        # self.stop_bofang.setIcon(icon1)
        # self.stop_bofang.setIconSize(QtCore.QSize(20, 20))
        # self.stop_bofang.setObjectName("stop_bofang")
        # self.gridLayout.addWidget(self.stop_bofang, 0, 2, 1, 1)
        # self.rebegin = QtWidgets.QPushButton(self)
        # self.rebegin.setMinimumSize(QtCore.QSize(0, 20))
        # self.rebegin.setMaximumSize(QtCore.QSize(100, 40))
        # self.rebegin.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        # self.rebegin.setStyleSheet("#rebegin{\n"
        #                            "    background-color:transparent;\n"
        #                            "    border-radius:10px;\n"
        #                            "border-color:white\n"
        #                            "}")
        # icon2 = QtGui.QIcon()
        # icon2.addPixmap(QtGui.QPixmap("./imgs/rebegin.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        # self.rebegin.setIcon(icon2)
        # self.rebegin.setIconSize(QtCore.QSize(22, 22))
        # self.rebegin.setObjectName("rebegin")
        # self.gridLayout.addWidget(self.rebegin, 1, 2, 1, 1)
        self.vbox.addLayout(self.gridLayout)

        self.recorder = RecorderWidget()
        self.recorder.setRecordTitle(self.name)
        self.vbox.addWidget(self.recorder)

        self.retranslateUi()

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.bofang.setText(_translate("self", "播放题目"+str(self.name)))
        # self.stop_bofang.setText(_translate("self", "暂停播放"))
        # self.rebegin.setText(_translate("self", "重新播放"))
        self.tingli_text.setPlainText(self.problemText)
        self.bofang.clicked.connect(self.say)

    def say(self):
        self.t = TextReader()
        self.t.say(self.problemText)


